﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace OAuth.Dapper.Models
{
    public partial class db_oauthContext : DbContext
    {
        public db_oauthContext()
        {
        }

        public db_oauthContext(DbContextOptions<db_oauthContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Account> Account { get; set; }
        public virtual DbSet<AccountLogin> AccountLogin { get; set; }
        public virtual DbSet<AccountPlatform> AccountPlatform { get; set; }
        public virtual DbSet<Client> Client { get; set; }
        public virtual DbSet<ClientClaim> ClientClaim { get; set; }
        public virtual DbSet<ClientConfig> ClientConfig { get; set; }
        public virtual DbSet<ClientProperty> ClientProperty { get; set; }
        public virtual DbSet<Grant> Grant { get; set; }
        public virtual DbSet<Resource> Resource { get; set; }
        public virtual DbSet<Secret> Secret { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
                optionsBuilder.UseMySql("server=localhost;userid=root;pwd=123q;port=3306;database=db_oauth;sslmode=none;");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Account>(entity =>
            {
                entity.ToTable("account");

                entity.Property(e => e.Id).HasColumnType("int(36)");

                entity.Property(e => e.AuthTypes).HasColumnType("tinyint(32)");

                entity.Property(e => e.CreateTime)
                    .HasColumnType("timestamp")
                    .HasDefaultValueSql("'CURRENT_TIMESTAMP'")
                    .ValueGeneratedOnAddOrUpdate();

                entity.Property(e => e.Email).HasColumnType("varchar(128)");

                entity.Property(e => e.EncryptionType).HasColumnType("tinyint(16)");

                entity.Property(e => e.LastLoginTime).HasColumnType("timestamp");

                entity.Property(e => e.Mobile)
                    .IsRequired()
                    .HasColumnType("varchar(16)");

                entity.Property(e => e.Name)
                    .IsRequired()
                    .HasColumnType("varchar(64)");

                entity.Property(e => e.Password)
                    .IsRequired()
                    .HasColumnType("varchar(128)");

                entity.Property(e => e.PasswordSalt)
                    .IsRequired()
                    .HasColumnType("varchar(128)");

                entity.Property(e => e.State).HasColumnType("tinyint(16)");

                entity.Property(e => e.Type).HasColumnType("tinyint(32)");
            });

            modelBuilder.Entity<AccountLogin>(entity =>
            {
                entity.ToTable("account_login");

                entity.Property(e => e.Id).HasColumnType("int(36)");

                entity.Property(e => e.AccountId).HasColumnType("int(11)");

                entity.Property(e => e.AccountType).HasColumnType("tinyint(16)");

                entity.Property(e => e.ClientIp)
                    .IsRequired()
                    .HasColumnType("varchar(128)");

                entity.Property(e => e.CreateTime)
                    .HasColumnType("timestamp")
                    .HasDefaultValueSql("'CURRENT_TIMESTAMP'")
                    .ValueGeneratedOnAddOrUpdate();

                entity.Property(e => e.PlatformType).HasColumnType("tinyint(16)");

                entity.Property(e => e.Remark).HasColumnType("varchar(255)");

                entity.Property(e => e.State).HasColumnType("tinyint(16)");

                entity.Property(e => e.UserAgent)
                    .IsRequired()
                    .HasColumnType("varchar(1024)");
            });

            modelBuilder.Entity<AccountPlatform>(entity =>
            {
                entity.ToTable("account_platform");

                entity.Property(e => e.Id).HasColumnType("int(36)");

                entity.Property(e => e.AccessToken).HasColumnType("varchar(1024)");

                entity.Property(e => e.AccountId)
                    .IsRequired()
                    .HasColumnType("varchar(36)");

                entity.Property(e => e.Avatar).HasColumnType("varchar(1024)");

                entity.Property(e => e.CreateTime)
                    .HasColumnType("timestamp")
                    .HasDefaultValueSql("'0000-00-00 00:00:00'");

                entity.Property(e => e.ExpiredTime).HasColumnType("timestamp");

                entity.Property(e => e.LoginTime).HasColumnType("timestamp");

                entity.Property(e => e.Nick).HasColumnType("varchar(128)");

                entity.Property(e => e.OpenId)
                    .IsRequired()
                    .HasColumnType("varchar(128)");

                entity.Property(e => e.RefreshToken).HasColumnType("varchar(1024)");

                entity.Property(e => e.State).HasColumnType("tinyint(16)");

                entity.Property(e => e.Type).HasColumnType("tinyint(16)");

                entity.Property(e => e.UnionId).HasColumnType("varchar(128)");
            });

            modelBuilder.Entity<Client>(entity =>
            {
                entity.ToTable("client");

                entity.Property(e => e.Id).HasColumnType("int(36)");

                entity.Property(e => e.AbsoluteRefreshTokenLifetime).HasColumnType("int(11)");

                entity.Property(e => e.AccessTokenLifetime).HasColumnType("int(11)");

                entity.Property(e => e.AccessTokenType).HasColumnType("int(11)");

                entity.Property(e => e.AllowAccessTokensViaBrowser).HasColumnType("tinyint(1)");

                entity.Property(e => e.AllowOfflineAccess).HasColumnType("tinyint(1)");

                entity.Property(e => e.AllowPlainTextPkce).HasColumnType("tinyint(1)");

                entity.Property(e => e.AllowRememberConsent).HasColumnType("tinyint(1)");

                entity.Property(e => e.AlwaysIncludeUserClaimsInIdToken).HasColumnType("tinyint(1)");

                entity.Property(e => e.AlwaysSendClientClaims).HasColumnType("tinyint(1)");

                entity.Property(e => e.AuthorizationCodeLifetime).HasColumnType("int(11)");

                entity.Property(e => e.BackChannelLogoutSessionRequired).HasColumnType("tinyint(1)");

                entity.Property(e => e.BackChannelLogoutUri).HasColumnType("varchar(2000)");

                entity.Property(e => e.ClientClaimsPrefix).HasColumnType("varchar(200)");

                entity.Property(e => e.ClientId).HasColumnType("int(200)");

                entity.Property(e => e.ClientName).HasColumnType("varchar(200)");

                entity.Property(e => e.ClientUri).HasColumnType("varchar(2000)");

                entity.Property(e => e.ConsentLifetime).HasColumnType("int(11)");

                entity.Property(e => e.Description).HasColumnType("varchar(1000)");

                entity.Property(e => e.EnableLocalLogin).HasColumnType("tinyint(1)");

                entity.Property(e => e.Enabled).HasColumnType("tinyint(1)");

                entity.Property(e => e.FrontChannelLogoutSessionRequired).HasColumnType("tinyint(1)");

                entity.Property(e => e.FrontChannelLogoutUri).HasColumnType("varchar(2000)");

                entity.Property(e => e.IdentityTokenLifetime).HasColumnType("int(11)");

                entity.Property(e => e.IncludeJwtId).HasColumnType("tinyint(1)");

                entity.Property(e => e.LogoUri).HasColumnType("varchar(2000)");

                entity.Property(e => e.PairWiseSubjectSalt).HasColumnType("varchar(200)");

                entity.Property(e => e.ProtocolType)
                    .IsRequired()
                    .HasColumnType("varchar(200)");

                entity.Property(e => e.RefreshTokenExpiration).HasColumnType("int(11)");

                entity.Property(e => e.RefreshTokenUsage).HasColumnType("int(11)");

                entity.Property(e => e.RequireClientSecret).HasColumnType("tinyint(1)");

                entity.Property(e => e.RequireConsent).HasColumnType("tinyint(1)");

                entity.Property(e => e.RequirePkce).HasColumnType("tinyint(1)");

                entity.Property(e => e.SlidingRefreshTokenLifetime).HasColumnType("int(11)");

                entity.Property(e => e.UpdateAccessTokenClaimsOnRefresh).HasColumnType("tinyint(1)");
            });

            modelBuilder.Entity<ClientClaim>(entity =>
            {
                entity.ToTable("client_claim");

                entity.Property(e => e.Id).HasColumnType("int(36)");

                entity.Property(e => e.ClientId).HasColumnType("int(36)");

                entity.Property(e => e.Type)
                    .IsRequired()
                    .HasColumnType("varchar(255)");

                entity.Property(e => e.Value)
                    .IsRequired()
                    .HasColumnType("varchar(255)");
            });

            modelBuilder.Entity<ClientConfig>(entity =>
            {
                entity.ToTable("client_config");

                entity.Property(e => e.Id).HasColumnType("int(36)");
            });

            modelBuilder.Entity<ClientProperty>(entity =>
            {
                entity.ToTable("client_property");

                entity.Property(e => e.Id).HasColumnType("int(36)");

                entity.Property(e => e.ClientId).HasColumnType("int(36)");

                entity.Property(e => e.Key)
                    .IsRequired()
                    .HasColumnType("varchar(255)");

                entity.Property(e => e.Value)
                    .IsRequired()
                    .HasColumnType("varchar(255)");
            });

            modelBuilder.Entity<Grant>(entity =>
            {
                entity.ToTable("grant");

                entity.Property(e => e.Id).HasColumnType("varchar(200)");

                entity.Property(e => e.ClientId)
                    .IsRequired()
                    .HasColumnType("varchar(200)");

                entity.Property(e => e.CreateTime)
                    .HasColumnType("timestamp")
                    .HasDefaultValueSql("'CURRENT_TIMESTAMP'")
                    .ValueGeneratedOnAddOrUpdate();

                entity.Property(e => e.Data).HasColumnType("text");

                entity.Property(e => e.ExpiredTime).HasColumnType("timestamp");

                entity.Property(e => e.SubjectId).HasColumnType("varchar(200)");

                entity.Property(e => e.Type)
                    .IsRequired()
                    .HasColumnType("varchar(50)");
            });

            modelBuilder.Entity<Resource>(entity =>
            {
                entity.ToTable("resource");

                entity.Property(e => e.Id).HasColumnType("int(36)");

                entity.Property(e => e.Description).HasColumnType("text");

                entity.Property(e => e.Emphasize).HasColumnType("tinyint(1)");

                entity.Property(e => e.Enabled).HasColumnType("tinyint(1)");

                entity.Property(e => e.Name)
                    .IsRequired()
                    .HasColumnType("varchar(128)");

                entity.Property(e => e.Required).HasColumnType("tinyint(1)");

                entity.Property(e => e.ShowInDiscoveryDocument).HasColumnType("tinyint(1)");

                entity.Property(e => e.Title)
                    .IsRequired()
                    .HasColumnType("varchar(512)");

                entity.Property(e => e.Type).HasColumnType("smallint(6)");
            });

            modelBuilder.Entity<Secret>(entity =>
            {
                entity.ToTable("secret");

                entity.Property(e => e.Id).HasColumnType("int(36)");

                entity.Property(e => e.Data)
                    .IsRequired()
                    .HasColumnType("varchar(2048)");

                entity.Property(e => e.ExpiredTime).HasColumnType("timestamp(6)");

                entity.Property(e => e.Source).HasColumnType("smallint(6)");

                entity.Property(e => e.SourceId).HasColumnType("int(36)");

                entity.Property(e => e.Title).HasColumnType("varchar(255)");

                entity.Property(e => e.Type)
                    .IsRequired()
                    .HasColumnType("varchar(64)");
            });
        }
    }
}
